<template>
	<view class="container">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<view class="swiper-tab-item" :class="{ on: dataType === 'not_use' }" data-current="not_use" @tap="swichNav">未使用</view>
			<view class="swiper-tab-item" :class="{ on: dataType === 'is_use' }" data-current="is_use" @tap="swichNav">已使用</view>
			<view class="swiper-tab-item" :class="{ on: dataType === 'is_expire' }" data-current="is_expire" @tap="swichNav">已过期</view>
		</view>
		<scroll-view :scroll-y="true" :style="{ height: swiperHeight + 'px' }">
			<view class="coupon-list" v-if="list.length">
				<view class="coupon-item" v-for="(item, index) in list" :key="index">
					<view :class="'item-wrapper color__' + (item.state.value ? item.color.text : 'gray')">
						<view class="coupon-type">{{ item.coupon_type.text }}</view>
						<view class="tip dis-flex flex-dir-column flex-x-center">
							<view v-if="item.coupon_type.value == 10">
								<text class="f-30">￥</text>
								<text class="money">{{ item.reduce_price }}</text>
							</view>
							<text class="money" v-if="item.coupon_type.value == 20">{{ item.discount }}折</text>
							<text class="pay-line">满{{ item.min_price }}元可用</text>
						</view>
						<view class="split-line"></view>
						<view class="content dis-flex flex-dir-column flex-x-between">
							<view class="title">{{ item.name }}</view>
							<view class="bottom dis-flex flex-y-center">
								<view class="time flex-box">
									<text class="f-24">{{ item.start_time.text }}~{{ item.end_time.text }}</text>
								</view>
								<view class="state">
									<text class="f-24">{{ item.state.text }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="yoshop-notcont" v-else-if="notcont">
				<text class="iconfont icon-wushuju"></text>
				<text class="cont">亲，暂无优惠券哦</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 选项卡标示
			dataType: 'not_use',

			// 列表高度
			swiperHeight: 0,

			// 优惠券列表
			list: [],

			// show
			notcont: false
		};
	},
	onLoad() {
		this.setSwiperHeight();
	},
	onShow() {
		this.getCouponList();
	},
	methods: {
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = uni.getSystemInfoSync();
			let tapHeight = uni.upx2px(80) + 1;
			this.swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
		},
		/**
		 * 获取优惠券列表
		 */
		getCouponList() {
			this.$get(
				this.$api.getuserCouponLists,
				{
					data_type: this.dataType
				},
				res => {
					this.list = res.data.list;
					this.notcont = !res.data.list.length;
				}
			);
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			this.list = {};
			this.dataType = e.target.dataset.current;
			this.$nextTick(() => {
				this.getCouponList();
			});
		}
	}
};
</script>
<style>
/* 选项卡 */

.swiper-tab {
	width: 100%;
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
}

.swiper-tab .swiper-tab-item {
	width: 33.333333%;
	height: 100%;
	font-size: 28rpx;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #f74c45;
	border-bottom: 2px solid #f74c45;
}

/* 设置scroll-view容器高度 */

.coupon-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 评论列表 */

.coupon-list {
	padding: 20rpx;
	box-sizing: border-box;
}

.coupon-list .coupon-item {
	position: relative;
	overflow: hidden;
	margin-bottom: 22rpx;
}

.coupon-list .coupon-item .item-wrapper {
	width: 100%;
	display: flex;
	background: #fff;
	border-radius: 8rpx;
	color: #fff;
	height: 180rpx;
}

.coupon-list .coupon-item .item-wrapper .coupon-type {
	position: absolute;
	top: 0;
	right: 0;
	z-index: 10;
	width: 128rpx;
	padding: 3px 0;
	background: #a771ff;
	font-size: 20rpx;
	text-align: center;
	color: #fff;
	transform: rotate(45deg);
	transform-origin: 64rpx 64rpx;
}

.coupon-list .coupon-item .item-wrapper.color__blue {
	background: linear-gradient(-125deg, #57bdbf, #2f9de2);
}

.coupon-list .coupon-item .item-wrapper.color__red {
	background: linear-gradient(-128deg, #ff6d6d, #ff3636);
}

.coupon-list .coupon-item .item-wrapper.color__violet {
	background: linear-gradient(-113deg, #ef86ff, #b66ff5);
}

.coupon-list .coupon-item .item-wrapper.color__violet .coupon-type {
	background: #55b5ff;
}

.coupon-list .coupon-item .item-wrapper.color__yellow {
	background: linear-gradient(-141deg, #f7d059, #fdb054);
}

.coupon-list .coupon-item .item-wrapper.color__gray {
	background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
}

.coupon-list .coupon-item .item-wrapper.color__gray .coupon-type {
	background: #9e9e9e;
}

.coupon-list .coupon-item .item-wrapper .content {
	flex: 1;
	padding: 30rpx 20rpx;
	border-radius: 8px 0 0 8px;
}

.coupon-list .coupon-item .item-wrapper .content .title {
	font-size: 34rpx;
}

.coupon-list .coupon-item .item-wrapper .tip {
	position: relative;
	flex: 0 0 32%;
	text-align: center;
	border-radius: 0 8px 8px 0;
}

.coupon-list .coupon-item .item-wrapper .tip .money {
	font-weight: bold;
	font-size: 52rpx;
}

.coupon-list .coupon-item .item-wrapper .tip .pay-line {
	font-size: 22rpx;
}

.coupon-list .coupon-item .item-wrapper .split-line {
	position: relative;
	flex: 0 0 0;
	border-left: 4rpx solid #fff;
	margin: 0 5px 0 3px;
	background: #fff;
}

.coupon-list .coupon-item .item-wrapper .split-line:before,
.coupon-list .coupon-item .item-wrapper .split-line:after {
	content: '';
	position: absolute;
	width: 12px;
	height: 6px;
	background: #f7f7f7;
	left: -7px;
	z-index: 1;
}

.coupon-list .coupon-item .item-wrapper .split-line:before {
	border-radius: 0 0 8px 8px;
	top: 0;
}

.coupon-list .coupon-item .item-wrapper .split-line:after {
	border-radius: 8px 8px 0 0;
	bottom: 0;
}

/* 没有更多 */

.no-more {
	text-align: center;
	color: #737373;
	padding: 10px 0;
}
</style>
